using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Net;

namespace Tetrazune
{
    public class ScoreTransfer
    {
        public event ScoreTransferCompleteEventHandler ScoreTransferComplete;
        public event EventHandler ScoreTransferFailed;

        HighScore score;
        NetworkSession sess;
        bool begun = false;

        public ScoreTransfer(HighScore sendScore)
        {
            score = sendScore;
        }

        public void Begin()
        {
            if (begun)
                throw new ApplicationException("Begin() cannot be called again until transfer is complete or fails.");
            begun = true;

            AvailableNetworkSessionCollection seshuns = 
                NetworkSession.Find(NetworkSessionType.SystemLink, 1, null);
            if (seshuns.Count < 1)
                HostSession();
            else
                JoinSession(seshuns[0]);
             

        }

        private void JoinSession(AvailableNetworkSession availableNetworkSession)
        {
            sess = NetworkSession.Join(availableNetworkSession);
            
        }

        private void HostSession()
        {
            throw new NotImplementedException();
        }


    }

    public delegate void ScoreTransferCompleteEventHandler(object sender, ScoreTransferCompleteEventArgs e);

    public class ScoreTransferCompleteEventArgs : EventArgs
    {
        HighScore[] scores;
        public ScoreTransferCompleteEventArgs(HighScore[] receievedScores)
        {
            scores = receievedScores;
        }
        public HighScore[] Scores
        {
            get { return scores; }
        }
    }

}